package com.coderman.common.starter.nacos.datajson;

import com.alibaba.fastjson.JSON;
import com.coderman.common.starter.nacos.datajson.config.ConfigFieldBean;
import com.coderman.common.starter.nacos.datajson.config.NacosConfigBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        NacosConfigBean nacosConfigBean = new NacosConfigBean();
        nacosConfigBean.setClassSimpleName("NacosConfigBean");
        nacosConfigBean.setDesc("测试JSON序列化\n/反序列化\n");
        nacosConfigBean.setDataId("com.coderman.datajson.serviceName");
        nacosConfigBean.setGroupId("NacosConfigBean");
        List<ConfigFieldBean> configFieldBeanList = new ArrayList<>();
        ConfigFieldBean configFieldBean = new ConfigFieldBean();
        configFieldBean.setQueryKey(true);
        configFieldBean.setDesc("XXX编码");
        configFieldBean.setFieldName("xxCode");
        configFieldBeanList.add(configFieldBean);
        ConfigFieldBean configFieldBean2 = new ConfigFieldBean();
        configFieldBean2.setQueryKey(false);
        configFieldBean2.setDesc("XXX编码2");
        configFieldBean2.setFieldName("xxCode2");
        configFieldBeanList.add(configFieldBean2);
        nacosConfigBean.setConfigFieldBeanList(configFieldBeanList);

        String jsonStr = JSON.toJSONString(nacosConfigBean);
        Class clazz = NacosConfigBean.class;
        Object nacosConfigBean1 =  JSON.parseObject(jsonStr,clazz);
        NacosConfigBean nacosConfigBean2 = (NacosConfigBean) nacosConfigBean1;
        System.out.println(JSON.toJSONString(nacosConfigBean2));

        String x = "{\"classSimpleName\":\"FeeCodeConfigEntity\",\"clazz\":\"com.coderman.common.starter.entity.FeeCodeConfigEntity\",\"configFieldBeanList\":[{\"desc\":\"主键ID\",\"fieldName\":\"id\",\"queryKey\":false},{\"desc\":\"费用项编码\",\"fieldName\":\"feeCode\",\"queryKey\":false},{\"desc\":\"费用项名称\",\"fieldName\":\"feeName\",\"queryKey\":false},{\"desc\":\"状态\",\"fieldName\":\"status\",\"queryKey\":false}],\"dataId\":\"com.coderman.common.starter.entity.FeeCodeConfigEntity\",\"desc\":\"feecode配置数据\",\"groupId\":\"commonstarterDemo-FeeCodeConfigEntity\"}";
        Object nacosConfigBean4 =  JSON.parseObject(x,clazz);
        NacosConfigBean nacosConfigBean3 = (NacosConfigBean) nacosConfigBean4;
        System.out.println(JSON.toJSONString(nacosConfigBean3));
    }
}
